package com.java.day06.homework;

import java.util.Random;

/**
 * 创建一个子类：战士， 独有的属性，怒气值。独有的方法，英勇打击，（攻击力=力量的上下百分之20*2，消耗20怒气）。
 */

public class Warrior extends Hero {
    //怒气值
    private int anger;


    //构造方法

    public Warrior(){

    }

    public Warrior(String name) {
        super(name);
        this.anger = 100;
    }

    public Warrior(String name, double strength, double wit, double agility, int anger) {
        super(name, strength, wit, agility);
        this.anger = anger;
    }


    //实例方法

    //英勇打击
    public void strikeValiantly(){
        if(anger>20){
            //攻击力
            double atack ;
            //随机数
            int num;
            Random random = new Random();
            num = random.nextInt(2);
            if(num>0){
                atack = (getStrength()+getStrength()*0.2)*2;
            }else{
                atack = (getStrength()-getStrength()*0.2)*2;
            }
            //释放技能怒气值减少
            anger = anger-20;
            System.out.println(getName()+"使用英勇打击造成"+atack+"点伤害");
        }else{
            System.out.println("怒气值不足,无法释放技能");
        }
    }

    public int getAnger() {
        return anger;
    }

    public void setAnger(int anger) {
        if(100>anger||anger<0){
            System.out.println("敏捷值非法,使用默认怒气值100");
            this.anger = 100;
        }else{
            this.anger = anger;
        }

    }

     @Override
    public String toString() {
        return "Warrior{" +
                "anger=" + anger +
                ", name='" + getName() + '\'' +
                ", strength=" + getStrength() +
                ", wit=" + getWit() +
                ", agility=" + getAgility() +
                '}';
    }
}
